public class Command {
	
	public void shell(String cmd) {
			
			String cmds[];
									
			cmds = cmd.split(":");
			
			if (cmds[0].equals("saveuser")) {
				if (cmds.length == 4) {
					User user = new User(cmds[1], cmds[2], cmds[3]);
					user.save();
					System.out.print("1");
				}
				else if (cmds.length == 5) {
					User user = new User(cmds[2], cmds[3], cmds[4]);
					user.setId(Integer.valueOf(cmds[1]));
					user.save();
					System.out.print("1");
				}
				else {
					System.out.println("error: createuser:name:email:password");
				}
			}
			if (cmds[0].equals("loaduser")) {
				if (cmds.length >= 2) {
					Auxiliar aux = new Auxiliar();
					aux.loadUser(Integer.valueOf(cmds[1]));					
				}
				else {
					System.out.println("error: createuser:name:email:password");
				}
			}
			if (cmds[0].equals("login")) {
				if (cmds.length >= 3) {
					Auxiliar aux = new Auxiliar();
					aux.login(cmds[1], cmds[2]);
				}
				else {
					System.out.println("error: login:email:pass");	
				}
			}
			if (cmds[0].equals("createserver")) {
				if (cmds.length >= 5) {
					Auxiliar aux = new Auxiliar();
					Map m = new Map(Integer.parseInt(cmds[3]));    //gera um mapa 20x20
					m.save();
					User u = aux.loadUserObj(Integer.parseInt(cmds[1]));
					Game g = new Game(m, cmds[2], u, Integer.parseInt(cmds[4]));
					g.save();			
					System.out.print(g.getId());
				}
				else {
					System.out.println("error: createserver:username:gamename:mapsize:gamecolor");	
				}									
			}
			if (cmds[0].equals("joinserver")) {
				if (cmds.length >= 3) {
					Auxiliar aux = new Auxiliar();
					aux.joinServer(Integer.parseInt(cmds[1]), Integer.parseInt(cmds[2]), Integer.parseInt(cmds[3]));
					System.out.println(1);
				}
				else {
					System.out.println("error: createserver:game:user:color");	
				}									
			}
			
			if (cmds[0].equals("createcomponent")) {
				if (cmds.length >= 6) {
					Auxiliar aux = new Auxiliar();
					User user = aux.loadUserObj(Integer.parseInt(cmds[2]));
					Map map = aux.loadMap(Integer.parseInt(cmds[1]));
					aux.createComponent(user, map, cmds[3], Integer.parseInt(cmds[4]), Integer.parseInt(cmds[5]));
					System.out.println(1);
				}
				else {
					System.out.println("error: createcomponent:game:username:type:x:y");	
				}									
			}
			
			if (cmds[0].equals("move")) {
				if (cmds.length >= 6) {
					Auxiliar aux = new Auxiliar();
					//User user = aux.loadUserObj(Integer.parseInt(cmds[2]));
					Map map = aux.loadMap(Integer.parseInt(cmds[1]));
					Component c = aux.loadComponent(Integer.parseInt(cmds[3]));
					aux.moveComponent(map, c, Integer.parseInt(cmds[4]), Integer.parseInt(cmds[5]));
					System.out.println(1);
				}
				else {
					System.out.println("error: move:game:user:component:x:y");	
				}									
			}
			if (cmds[0].equals("attack")) {
				if (cmds.length >= 6) {
					Auxiliar aux = new Auxiliar();
					User user = aux.loadUserObj(Integer.parseInt(cmds[2]));
					Map map = aux.loadMap(Integer.parseInt(cmds[1]));
					Component c = aux.loadComponent(Integer.parseInt(cmds[3]));
					aux.attack(user, map, c, Integer.parseInt(cmds[4]), Integer.parseInt(cmds[5]));
					System.out.println(1);
				}
				else {
					System.out.println("error: attack:game:user:component:x:y");	
				}									
			}
			if (cmds[0].equals("endturn")) {
				if (cmds.length >= 3) {
					Auxiliar aux = new Auxiliar();
					User user = aux.loadUserObj(Integer.parseInt(cmds[2]));
					aux.endTurn(Integer.parseInt(cmds[1]), user);
					System.out.println(1);
				}
				else {
					System.out.println("error: endturn:game:user");	
				}									
			}
			if (cmds[0].equals("turnuser")) {
				if (cmds.length >= 2) {
					Auxiliar aux = new Auxiliar();
					System.out.println(aux.turnUser(Integer.parseInt(cmds[1])));
				}
				else {
					System.out.println("error: turnuser:game");	
				}									
			}
			if (cmds[0].equals("loadmap")) {
				if (cmds.length >= 2) {
					Auxiliar aux = new Auxiliar();
					Map map = aux.loadMap(Integer.parseInt(cmds[1]));
					map.print();
				}
				else {
					System.out.println("error: loadmap:game");	
				}
			}
			if (cmds[0].equals("gamestatus")) {
				if (cmds.length >= 2) {
					Auxiliar aux = new Auxiliar();
					System.out.println(aux.gameStatus(Integer.parseInt(cmds[1])));					
				}
				else {
					System.out.println("error: gamestatus:game");	
				}									
			}
			if (cmds[0].equals("listserver")) {
				if (cmds.length >= 2) {
					Auxiliar aux = new Auxiliar();
					aux.listServer(Integer.parseInt(cmds[1]));
				}
				else {
					System.out.println("error: listserver:status");	
				}									
			}
			if (cmds[0].equals("ranking")) {
				if (cmds.length >= 2) {
					Auxiliar aux = new Auxiliar();
					aux.ranking();
				}
				else {
					System.out.println("error: ranking:type");	
				}									
			}
	}
	
}
